package cn.bgs.controller;

import cn.bgs.pojo.Dormitory;
import cn.bgs.service.DormitoryService;
import com.github.pagehelper.PageInfo;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class DormitoryController {
    @Autowired private DormitoryService dormitoryService;

    @RequestMapping("/findAllDormitory")
    public String findAllDormitory(Model m, @RequestParam (defaultValue = "1")Integer pageNum){

        Integer pageSize=3;

        PageInfo<Dormitory> list=dormitoryService.findAll(pageNum,pageSize);
        m.addAttribute("p",list);


        return "/dormitory/dormitoryList";

    }

    @RequestMapping("/deleteDor")
    public String deleteDor(Integer pkId){
        dormitoryService.deleteDor(pkId);
        return "redirect:/findAllDormitory";

    }

    @RequestMapping("/updateByIdDor")
    public String updateByIdDor(Model m,Integer pkId){

        Dormitory dormitory=dormitoryService.selectByPrimaryKey(pkId);
        m.addAttribute("list",dormitory);

        return "/dormitory/dormitoryModify";

    }

    @RequestMapping("/updateDor")
    public String updateDor(Dormitory record){

        int ff=dormitoryService.updateByPrimaryKeySelective(record);

        return "redirect:/findAllDormitory";

    }

    @RequestMapping("/queryDor")
    public String queryDor(Model m, @RequestParam (defaultValue = "1")Integer pageNum,Dormitory dormitory){
        Integer pageSize=100;

        PageInfo<Dormitory> list=dormitoryService.queryDor(pageNum,pageSize,dormitory);
        m.addAttribute("p",list);


        return "/dormitory/dormitoryList";



    }



}
